
// 窗口
/**
 * @method _refreshCursor
 * @private
 */

 
Window.prototype._refreshCursor = function() {
    var pad = this._padding;
    var x = this._cursorRect.x + pad - this.origin.x;
    var y = this._cursorRect.y + pad - this.origin.y;
    var w = this._cursorRect.width;
    var h = this._cursorRect.height;
    var m = 12;
    var x2 = Math.max(x, pad);
    var y2 = Math.max(y, pad);
    var ox = x - x2;
    var oy = y - y2;
    var w2 = Math.min(w, this._width - pad - x2);
    var h2 = Math.min(h, this._height - pad - y2);
    var bitmap = new Bitmap(w2, h2);

    this._windowCursorSprite.bitmap = bitmap;
    this._windowCursorSprite.setFrame(0, 0, w2, h2);
    this._windowCursorSprite.move(x2, y2);

    if (w > 0 && h > 0 && this._windowskin) {
        var skin = this._windowskin;
        var p = 96;
        var q = 48;
        bitmap.blt(skin, p+m, p+m, q-m*2, q-m*2, ox+m, oy+m, w-m*2, h-m*2);
        bitmap.blt(skin, p+m, p+0, q-m*2, m, ox+m, oy+0, w-m*2, m);
        bitmap.blt(skin, p+m, p+q-m, q-m*2, m, ox+m, oy+h-m, w-m*2, m);
        bitmap.blt(skin, p+0, p+m, m, q-m*2, ox+0, oy+m, m, h-m*2);
        bitmap.blt(skin, p+q-m, p+m, m, q-m*2, ox+w-m, oy+m, m, h-m*2);
        bitmap.blt(skin, p+0, p+0, m, m, ox+0, oy+0, m, m);
        bitmap.blt(skin, p+q-m, p+0, m, m, ox+w-m, oy+0, m, m);
        bitmap.blt(skin, p+0, p+q-m, m, m, ox+0, oy+h-m, m, m);
        bitmap.blt(skin, p+q-m, p+q-m, m, m, ox+w-m, oy+h-m, m, m);
    }
};

/**
 * @method _refreshFrame
 * @private
 */

Window.prototype._refreshFrame = function() {
    const w = this._width;
    const h = this._height;
    const m = 24;	//边框宽度
    const bitmap = new Bitmap(w, h);

    this._windowFrameSprite.bitmap = bitmap;
    this._windowFrameSprite.setFrame(0, 0, w, h);

    if (w > 0 && h > 0 && this._windowskin) {
        const skin = this._windowskin;
        const p = 96;	//边框起始横坐标
        const q = 96;	//边框终止纵坐标
		const nx = parseInt(w/(p-m*2));
		const ny = parseInt(h/(p-m*2));
		const mx = w%(p-m*2);
		const my = h%(p-m*2);
		
		for(let i=0; i<nx; i++){
			bitmap.blt(skin, p+m, 0+0, p-m*2, m, m+i*(p-m*2), 0, (p-m*2), m);		// 上
			bitmap.blt(skin, p+m, 0+q-m, p-m*2, m, m+i*(p-m*2), h-m, (p-m*2), m);	// 下
		}
		if (mx != 0){
			bitmap.blt(skin, p+m, 0+0, mx, m, m+i*(p-m*2), 0, mx, m);		// 上
			bitmap.blt(skin, p+m, 0+q-m, mx, m, m+i*(p-m*2), h-m, mx, m);	// 下
		}
		
        for(let i=0; i<ny; i++){
			bitmap.blt(skin, p+0, 0+m, m, p-m*2, 0, m+i*(p-m*2), m, (p-m*2));		// 左
			bitmap.blt(skin, p+q-m, 0+m, m, p-m*2, w-m, m+i*(p-m*2), m, (p-m*2));	// 右
		}
		if (my != 0){
			bitmap.blt(skin, p+0, 0+m, m, my, 0, m+i*(p-m*2), m, my);		// 左
			bitmap.blt(skin, p+q-m, 0+m, m, my, w-m, m+i*(p-m*2), m, my);	// 右
		}
		
        bitmap.blt(skin, p+0, 0+0, m, m, 0, 0, m, m);				// 左上
        bitmap.blt(skin, p+q-m, 0+0, m, m, w-m, 0, m, m);			// 右上
        bitmap.blt(skin, p+0, 0+q-m, m, m, 0, h-m, m, m);			// 左下
        bitmap.blt(skin, p+q-m, 0+q-m, m, m, w-m, h-m, m, m);		//右下
    }
};

// 刷新光标不透明度
/**
 * @method _updateCursor
 * @private
 */
Window.prototype._updateCursor = function() {
	if (this.cursorOpacity == 0){
		var cursorOpacity = this.cursorOpacity;
	}else{
		var cursorOpacity = this.contentsOpacity;
	}
    this._windowCursorSprite.alpha = cursorOpacity / 255;
    this._windowCursorSprite.visible = this.isOpen();
};

// 光标不透明度
/**
 * The opacity of the window cursor (0 to 255).
 *
 * @property cursorOpacity
 * @type Number
 */
 
Object.defineProperty(Window.prototype, 'cursorOpacity', {
    get: function() {
        return this._windowCursorSprite.alpha * 255;
    },
    set: function(value) {
        this._windowCursorSprite.alpha = value.clamp(0, 255) / 255;
    },
    configurable: true
});
